package com.monkey.luffer.springboot.demo.basis.kcc;

import com.alibaba.excel.EasyExcel;
import org.apache.commons.lang3.StringUtils;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author jiahong.liu
 */
public class CreateTable {
    public static void main(String[] args) throws IOException {
        List<List<String>> list = new ArrayList<>();
        File file = new File("/Users/jiahong.liu/Work/Task/db-file-table/table.txt");
        readFileByLine(file,list);
        EasyExcel.write("/Users/jiahong.liu/Work/Task/db-file-table/table.xlsx").sheet().doWrite(list);
    }

    public static void readFileByLine(File file, List<List<String>> list) throws IOException {
        FileInputStream inputStream = new FileInputStream(file);
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String str;
        boolean begin = false;
        boolean end = false;
        int count = 0;
        while((str = bufferedReader.readLine()) != null)
        {
            if(str.endsWith("(")) {
                begin = true;
                continue;
            }

            if (begin) {
                count++;
                List<String> tmpList = new ArrayList<>();
                tmpList.add(String.valueOf(count));
                begin(str, tmpList);
                list.add(tmpList);
            }

        }
    }


    private static void begin(String str, List<String> tmpList){
        String[] ele = str.split(" ");
        List<String> newList = new ArrayList<>();
        for (String tmp: ele) {
            if (StringUtils.isNotBlank(tmp)) {
                newList.add(tmp);
            }
        }

        if (newList.size() < 4) {
            return;
        }

        if (ele.length > 1) {
            tmpList.add(newList.get(0));
            tmpList.add(newList.get(1));
            if(str.contains("not") || str.contains("NOT")) {
                tmpList.add(newList.get(5));
                tmpList.add("Y");
                tmpList.add("N");
            } else {
                tmpList.add(newList.get(4));
                tmpList.add("Y");
                tmpList.add("Y");
            }


            tmpList.add("N");
            tmpList.add("/");

        }
    }
}
